const app = getApp();

Component({
	data: {
		active: 0,
		tabbarList: [],
		isShow: true//是否显示
	},


	methods: {

		onChange(event) {
			if (event.detail === 3 || event.detail === 2 || event.detail === 0 || event.detail === 4) {
				let e = { currentTarget: { dataset: {} } };
				e.currentTarget.dataset.url = this.data.tabbarList[event.detail].newsUrl;
				e.currentTarget.dataset.outLink = this.data.tabbarList[event.detail].outLink;
				e.currentTarget.dataset.newsId = this.data.tabbarList[event.detail].newsId;
				app.toOutLink(e);
			} else {
				if (!app.openLoginPage()) {
					let e = { currentTarget: { dataset: {} } };
					e.currentTarget.dataset.url = this.data.tabbarList[event.detail].newsUrl;
					e.currentTarget.dataset.outLink = this.data.tabbarList[event.detail].outLink;
					e.currentTarget.dataset.newsId = this.data.tabbarList[event.detail].newsId;
					app.toOutLink(e);
				}

			}

		},

		init() {
			if (!wx.getStorageSync('homeList')) return;
			this.setData({
				bottomHeight: app.globalData.bottomHeight,
				tabbarList: app.screenList(wx.getStorageSync('homeList'), 2).newsList
			});
			const page = getCurrentPages().pop();
			//console.log('tabbarList', this.data.tabbarList);
			
			this.setData({
				active: this.data.tabbarList.findIndex(item => item.newsUrl === `/${page.route}`)
			});
		},

		hide() {
			this.setData({
				isShow: false
			})
		},

		show() {
			this.setData({
				isShow: true
			})
		}

	}
});
